package cn.wolfcode.luowowo.comment.service.impl;

import cn.wolfcode.luowowo.comment.domain.ScenicComment;
import cn.wolfcode.luowowo.comment.repository.IScenicCommentRepository;
import cn.wolfcode.luowowo.comment.service.IScenicCommentService;
import com.alibaba.dubbo.config.annotation.Service;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.mongodb.core.MongoTemplate;

import java.util.Date;
import java.util.List;

@Service
public class ScenicCommentServiceImpl implements IScenicCommentService {
    @Autowired
    private IScenicCommentRepository repository;

    @Autowired
    private MongoTemplate template;

    @Override
    public ScenicComment addComment(ScenicComment comment) {
        comment.setCreateTime(new Date());//创建时间
        if(comment.getType()==1){//评论中有评论，找评论中的评论
            ScenicComment refComment = repository.findById(comment.getRefComment().getId()).get();
            comment.setRefComment(refComment);
        }
        repository.save(comment);//保存到mongodb中
        return comment;
    }

    @Override
    public List<ScenicComment> selectComment(Long detailId) {
        List<ScenicComment> comments = repository.findScenicCommentsBy(detailId);
        return comments;
    }
}
